package org.onion.pattern.event.springboot.rocketmq.consume.distribute;

import lombok.Getter;
import org.onion.pattern.event.springboot.rocketmq.config.RocketMessageMetadata;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;
import org.springframework.util.Assert;

/**
 * rocketmq 转 spring 消息事件
 */
public class RocketMQApplicationEvent<T> extends ApplicationEvent implements ResolvableTypeProvider {

    @Getter
    private final T                payload;
    @Getter
    private final RocketMessageMetadata metadata;

    public RocketMQApplicationEvent(T payload, RocketMessageMetadata metadata_) {
        super(payload);
        Assert.notNull(payload, "Payload must not be null");
        Assert.notNull(metadata_, "metadata must not be null");
        this.payload = payload;
        this.metadata = metadata_;
    }


    public ResolvableType getResolvableType() {
        return ResolvableType.forClassWithGenerics(this.getClass(), ResolvableType.forInstance(this.getPayload()));
    }

}
